package test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class DBUtils {

	public  Connection getConn() {
		Connection conn = null;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			String url = "jdbc:oracle:" + "thin:@121.248.200.5:1521:orcl";
			String user = "SLMETADATA";
			String password = "SLMETADATA";
			conn = DriverManager.getConnection(url, user, password);
			
			System.out.print("数据库连接成功！");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return conn;
	}
	
	
	public static void close(Connection conn, PreparedStatement st, ResultSet rs) {
	    closeRs(rs);
	    closeSt(st);
	    closeConn(conn);
	}
	
	public static void closeConn(Connection conn) {
	    try {
	      if (conn != null && !conn.isClosed()) {
	        conn.close();
	      }
	    } catch (Exception e) {
	      e.printStackTrace();
	    }
	}
	
	
	public static void closeSt(Statement st) {
	    try {
	      if (st != null) {
	        st.close();
	      }
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	 }
	
	
	public static void closeRs(ResultSet rs) {
	    try {
	      if (rs != null) {
	        rs.close();
	      }
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	}
	
	
	/*public static void main(String args[]){
		
		Connection conn = null;
		PreparedStatement pstmt = null;
		try{
			conn = getConn();
		}
		catch (Exception e) {
			e.printStackTrace();
		} finally {
			close(conn, pstmt, null);
		}
	}*/
	
}
